"""
文档注释
讲述字符串
"""

# s0 = 'hello'
# s1 = "hello"
# print(s0, s1, type(s0), type(s1))
# s3 = "i'm iron man"
# s4 = """hello
#
#                     this
#
#                     is
#
#                     def myfun():
#                         pass
#
# world"""
# print(type(s4))
# print(s4, end="")
# print("==============================")
#
#
# print('i\'m iron man')
# print("hell\"o world")
# print("第一行\n第二行")
# print("单元格\t单元格\t单元格\t单元格\t单元格\t单元格\t单元格")
# print("我\b是退格键\b")
#
# print("111111111111111111111111111111111111111111111111"
#       "1111111111111111111111111111111111111111111111111"
#       "1111111111111111111111111111111111111111111111111"
#       "1111111111111111111111111111111111111111111111111"
#       "1111111111111111111111111111111111111111111111111"
#       "11111")

# s10 = "welcome to china"
# print(len(s10))
# print(s10[0], s10[15])
# # index out of range  索引越界 [0, length-1]
# # print(s10[100])
# print(s10[-16], s10[-1])

# s20 = "宝岛台湾 是 中国不可分割的一部分"
# # 方法一： 不关注索引
# # for c in s20:
# #     print(c)
#
# # 方式二： 通过索引取到每一个元素
# length = len(s20)
# # print(length)
# for i in range(length):
#     print(s20[i])

# 查找元素第一次出现的位置
print("hello".index("l"))
print("hello".rindex("l"))
# index找不到报错  find找不到返回-1
print("hello".find("*"))
print("hello".rfind("l"))

# 统计个数
print("hello".count("ll*"))

# 单词首字母大写
print("hello world".title())
# 第一个字母大写
print("hello world".capitalize())
# 全变大写
print("hello world".upper())
# 全变小写
print("HELLO".lower())
# 大小写转换
print("heLLO World".swapcase())

# 剔除左右空白
print("    abc    def   ".strip())
print("    abc    def   ".lstrip())
print("    abc    def   ".rstrip())

# 切割
print("hello world".split("o"))
# 拼接
print("++++++".join("hello world"))

# 替换
print("hello world".replace("hello", "hi"))

# 以*开头 结尾
print("hello world".startswith("hi"))
print("hello world".endswith("ld"))

# 编码解码  方式一致
r = "中国".encode(encoding="gbk")
print(r, type(r))
r = r.decode(encoding="gbk")
print(r, type(r))

# 补齐
print("hello world".center(20, "*"))
print("hello world".ljust(20, "*"))
print("hello world".rjust(20, "*"))
print("hello world".zfill(20))

print("hello".isalpha())
print("123456".isdigit())

print("abcdabcdabcdacd".count("abc"))

print("+".join(["a", "b", "c"]))
print("+".join("abcdef"))

# -1
print("abcd".find("dabc"))
# 错误
# print("abcd".index("def"))

print("**".zfill(20))
print("123".isdigit())
print("abc".ljust(20, "*"))
print("abc".center(20, "*"))
print("abc".encode())
print("abc".encode().decode())

print("123".endswith("23"))
print("123".startswith("23"))

print("好好学习 天天向上".replace("向上", "**"))

print("hello this world".split("o"))
print("  admin".strip())

print("abcDef".swapcase())

print("abcDef".lower())

print("abcDef".upper())

print("abcDef abc\tabc\nabc".title())

print("abcDef".capitalize())


